home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / scheme2c / rec-28se.pat / sources / scrt / sparc.s
Encoding:
Text File  |  1994-06-30  |  3.0 KB  |  107 lines

  1. !
  2. ! Rules for building continuations on the SPARC:
  3. !
  4. ! 1 - register windows must be flushed to memory before
  5. !    the stack is copied to the heap.
  6. !
  7. ! 2 - setjmp must save the caller's local and input register
  8. !    frames when saving context, because longjmp will not
  9. !    have access to the saved stack to fetch the registers
  10. !    from their normal resting place.
  11. !
  12. ! 3 - longjmp must flush register windows so the correct register
  13. !    values will be reloaded from memory when execution continues
  14. !    on the restored stack.
  15. !
  16. ! 4 - longjmp must restore the caller's local and input register
  17. !    frames because the stack hasn't been restored when longjmp
  18. !    is called.
  19. !
  20.  
  21.  
  22. !
  23. ! This misnamed function is responsible for providing the
  24. ! top of stack address, via macro STACKPTR, to the continuation
  25. ! builder and the heap manager.  Because both of these functions
  26. ! immediately begin examining the memory on the stack, the register
  27. ! windows are flushed to memory so their values will be saved in
  28. ! heap allocated continuations and seen by the garbage collector.
  29. !
  30.     .global    _sc_processor_register
  31. _sc_processor_register:
  32.     ta    3            ! flush register windows
  33.     jmp    %o7+8            ! return
  34.     add    %sp, 0, %o0        ! return stack pointer
  35.  
  36. !
  37. ! Save the current environment in a heap allocated continuation.
  38. !
  39.     .global    _sc_setjmp
  40. _sc_setjmp:
  41.     st    %o6, [%o0 +  0]        ! save stack pointer
  42.     st    %o7, [%o0 +  4]        ! save continuation pointer
  43.     st    %g1, [%o0 +  8]        ! save global registers
  44.     st    %g2, [%o0 + 12]        ! these may be allocated for
  45.     st    %g3, [%o0 + 16]        ! caller saves registers or
  46.     st    %g4, [%o0 + 20]        ! for global values.
  47.     st    %g5, [%o0 + 24]
  48.     st    %g6, [%o0 + 28]
  49.     st    %g7, [%o0 + 32]
  50.     st    %l0, [%o0 + 36]        ! save local registers
  51.     st    %l1, [%o0 + 40]        ! the sunos setjmp uses
  52.     st    %l2, [%o0 + 44]        ! the register windows to
  53.     st    %l3, [%o0 + 48]        ! save these, we can't.
  54.     st    %l4, [%o0 + 52]
  55.     st    %l5, [%o0 + 56]
  56.     st    %l6, [%o0 + 60]
  57.     st    %l7, [%o0 + 64]
  58.     st    %i0, [%o0 + 68]
  59.     st    %i1, [%o0 + 72]
  60.     st    %i2, [%o0 + 76]
  61.     st    %i3, [%o0 + 80]
  62.     st    %i4, [%o0 + 84]
  63.     st    %i5, [%o0 + 88]
  64.     st    %i6, [%o0 + 92]
  65.     st    %i7, [%o0 + 96]
  66.     mov    %y, %o2            ! fetch %y, whatever it is
  67.     st    %o2, [%o0 + 100]    ! and save it
  68.     jmp    %o7+8            ! return
  69.     add    %g0, %g0, %o0        ! return 0
  70.  
  71. !
  72. ! Restore an environment from a heap allocated continuation.
  73. !
  74.     .global    _sc_longjmp
  75. _sc_longjmp:
  76.     ta    3            ! flush register windows
  77.     ld    [%o0 +  0], %o6        ! restore stack pointer
  78.     ld    [%o0 +  4], %o7        ! load continuation pointer
  79.     ld    [%o0 +  8], %g1        ! restore global registers
  80.     ld    [%o0 + 12], %g2
  81.     ld    [%o0 + 16], %g3
  82.     ld    [%o0 + 20], %g4
  83.     ld    [%o0 + 24], %g5
  84.     ld    [%o0 + 28], %g6
  85.     ld    [%o0 + 32], %g7
  86.     ld    [%o0 + 36], %l0        ! restore local frame from stack
  87.     ld    [%o0 + 40], %l1
  88.     ld    [%o0 + 44], %l2
  89.     ld    [%o0 + 48], %l3
  90.     ld    [%o0 + 52], %l4
  91.     ld    [%o0 + 56], %l5
  92.     ld    [%o0 + 60], %l6
  93.     ld    [%o0 + 64], %l7
  94.     ld    [%o0 + 68], %i0
  95.     ld    [%o0 + 72], %i1
  96.     ld    [%o0 + 76], %i2
  97.     ld    [%o0 + 80], %i3
  98.     ld    [%o0 + 84], %i4
  99.     ld    [%o0 + 88], %i5
  100.     ld    [%o0 + 92], %i6
  101.     ld    [%o0 + 96], %i7
  102.     ld    [%o0 + 100], %o2    ! restore %y, whatever it is
  103.     mov    %o2, %y
  104.     jmp    %o7+8            ! return
  105.     add    %o1, %g0, %o0        ! return arg
  106.  
  107.